<?php
    $page = $_GET['page'];

 if($page=='catalog')
 {

    // $con=mysql_connect("localhost","root","");
    //$db=mysql_select_db("db_lols",$con);
    require('db_connection.php');
    $materialID = $_GET['materialID'];
    $type = $_POST['type'];
    $callNo = $_POST['callNo'];
    $accessionNo = $_POST['accessionNo'];
    $title = $_POST['title'];
    $author = $_POST['author'];
    $subject = $_POST['subject'];
    $publisher = $_POST['publisher'];
    $placePub = $_POST['placePub'];
    $edition = $_POST['edition'];
    $isbn = $_POST['isbn'];
    $noOfPage = $_POST['noOfPage'];
    $width = $_POST['width'];
    $length = $_POST['length'];
    $acquisitionType = $_POST['acquisitionType'];
    $description = $_POST['description'];
    $copyNo = $_POST['copyNo'];
    $noOfDays = $_POST['noOfDays'];
    //$imgfilename=''];
    //echo $libraryNo;
    $new_file_name="$materialID.jpg";
    $path= "images/catalog/".$new_file_name;
    if($ufile !=none)
    {
    if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
    {
    echo "Successful<BR/>";

    //$new_file_name = new file name
    //$HTTP_POST_FILES['ufile']['size'] = file size
    //$HTTP_POST_FILES['ufile']['type'] = type of file
    echo "File Name :".$new_file_name."<BR/>";
    echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
    echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
    }
    else
    {
        echo "Error";
        $new_file_name="nophoto.jpg";
    }
    }
//     $sql = "SELECT * FROM tbllibrary";
//     $result = mysql_query($sql);
//     $ctr = mysql_num_rows($result)+1;
    $query = "UPDATE tblcollection SET callNo='$callNo',type='$type',subject='$subject',accessionNo='$accessionNo',title='$title',author='$author',publisher='$publisher',yearPub='$yearPub',placePub='$placePub',edition='$edition',isbn='$isbn',noOfPage='$noOfPage',width='$width',length='$length',acquisitionType='$acquisitionType',imgfilename='$new_file_name',description='$description',copyNo='$copyNo',noOfDays='noOfDays' WHERE materialID='$materialID'";

    //$query = "INSERT INTO tbllibrary VALUES ('$libraryName','$ctr','$address','$contactNo','$description','secret')";

    //$query = "UPDATE tbllibrary SET libraryName='$libraryName',libraryNo='$ctr',address='$address',contactNo='$contactNo',description='$description',imgfilename='secret' WHERE libraryNo=$libraryNo";

    $result = mysql_query($query);


    if($result){
       // echo("Record sucessfully edited.");
        //echo"'<script>document.location.href='catalogentry.php'</script>'";
        echo"'<script>document.location.href='catalogprint.php?materialID=$materialID'</script>'";
//             $host  = $_SERVER['HTTP_HOST'];
//           $uri  = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
//           $extra = 'catalogentry.php';
//           header("Location: http://$host$uri/$extra");



    }else{
       echo("Edit catalog failed.");
       echo"'<script>document.location.href='catalogentry.php'</script>'";
    }
    mysql_close();

}


?>
